(function (doc, window) {
    // 获取元素
    const plane = doc.querySelector('#plane')

    // 设置参数
    let deg = 0, ex = 0, ey = 0, vx = 0, vy = 0, count = 0
    const init = () => {
        bindEvent()
    }

    // 绑定事件
    function bindEvent() {
        window.addEventListener('mousemove', handleWindowMove)
    }

    // 事件函数
    function handleWindowMove(e) {
        ex = e.x - plane.offsetLeft - plane.clientWidth / 2
        ey = e.y - plane.offsetTop - plane.clientHeight / 2
        // 旋转角度
        deg = 360 * Math.atan(ey / ex) / (2 * Math.PI) + 45
        if (ex < 0) {
            deg += 180
        }
        count = 0
        console.log(ex, ey);
    }

    function draw() {
        plane.style.transform = 'rotate(' + deg + 'deg)';
        if (count < 100) {
            vx += ex / 100;
            vy += ey / 100;
        }
        plane.style.left = vx + 'px'
        plane.style.top = vy + 'px'
        count++
    }

    setInterval(draw, 1)

    init()
})(document, window)